package com.demo.api.system.factory;

import com.demo.api.system.service.RemoteUserService;
import com.demo.common.core.domain.SysUserWxBo;
import com.demo.common.core.result.R;
import com.demo.common.core.domain.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author demo
 */
@Component
@Slf4j
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService() {
            @Override
            public R<LoginUser> getUserInfoByUk(String username, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByMobile(String mobile, Boolean isRegister, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByMailbox(String mailbox, Boolean isRegister, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByWx(SysUserWxBo sysUserWxBo, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }
            @Override
            public R<Boolean> registerUserInfo(String uk, String pk, String source) {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getConfigInfo(String configKey, String source) {
                return R.fail("获取配置信息失败:" + throwable.getMessage());
            }
        };
    }
}
